uniform extern float4x4 gWVP;
uniform extern float4x4 gInvWorld;
uniform extern texture  gTex;
uniform extern float3   gEyePosW;

sampler Tex = sampler_state
{
	Texture = <gTex>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU  = CLAMP;
    AddressV  = CLAMP;
};

struct VSInput
{
    float3 posL      : POSITION0;
	float2 texc     : TEXCOORD0;
};

struct VSOutput
{
    float4 posH : POSITION0;
	float2 texc  : TEXCOORD0;
};

VSOutput BlasterCellVS(VSInput input)
{
	VSOutput output = (VSOutput)0;
	
	float4 eyePosL = mul(float4(gEyePosW, 1.0f), gInvWorld);
	float2 cellCenterProj = float2(0,0);
	
	float3 centerToEyeProj = float3(eyePosL.x - cellCenterProj.x, eyePosL.y - cellCenterProj.y, 0);
	float3 rotateVertDir = cross(normalize(centerToEyeProj), float3(0,0,1));
	rotateVertDir = normalize(rotateVertDir);
	
	float xIniDir = sign(input.posL.x);
	float3 posRotated = rotateVertDir * xIniDir * 150 + float3(0,0,input.posL.z);
	
	output.posH = mul(float4(posRotated, 1.0f), gWVP);
	output.texc = input.texc;

    return output;
}

float4 BlasterCellPS(VSOutput input) : COLOR0
{
    return tex2D(Tex, input.texc);
}

technique BlasterCell
{
    pass P0
    {
        AlphaBlendEnable = true;
        SrcBlend = One;
        DestBlend = One;
		ZWriteEnable = false;

        VertexShader = compile vs_1_1 BlasterCellVS();
        PixelShader = compile ps_1_1 BlasterCellPS();
    }
}
